﻿using System.Windows.Controls;
using MMK.Paket_Tracker.Runtime.BusinessEntities;
using MMK.Paket_Tracker.GUI.Views;
using MMK.Paket_Tracker.Runtime.Commands;


namespace MMK.Paket_Tracker.Runtime.Workflow
{
    /// <summary>
    /// Implements the workflow for PT app
    /// </summary>
    public static class PTWorkflow
    {
        /// <summary>
        /// Gets the next state for a given UC and command.
        /// </summary>
        /// <param name="notification">The notification.</param>
        /// <returns>An instance of the next UserControl to show</returns>
        public static UserControl GetNextState(MainWindowNotification notification)
        {
            UserControl result;

            switch (notification.UseCaseName)
            {
                case Views.START_WINDOW:
                    result = HandleStartWindow(notification);
                    break;

                case Views.GET_STATUS:
                    result = HandleGetStatusWindow(notification);
                    break;

                case Views.NEW_PACKET_ADDRESS_SENDER:
                    result = HandleNewPacketAddressSender(notification);
                    break;

                case Views.NEW_PACKET_ADDRESS_RECEIVER:
                    result = HandleNewPacketAddressReceiver(notification);
                    break;

                case Views.GET_WEIGHT:
                    result = HandleGetWeight(notification);
                    break;

                case Views.CHECK_DATA:
                    result = HandleCheckData(notification);
                    break;

                case Views.SENDPACKET_DATA:
                    result = HandleSendData(notification);
                    break;

                default:
                    result = null;
                    break;
            }

            return result;
        }

        private static UserControl HandleSendData(MainWindowNotification notification)
        {
            UserControl result = new StartWindow();
            return result;
        }


        private static UserControl HandleCheckData(MainWindowNotification notification)
        {
            UserControl result;

            switch (notification.Command.Name)
            {
                case Names.GoOn:
                    result = new SendPacketData();
                    break;

                default:
                    result = null;
                    break;
            }

            return result;
        }

        private static UserControl HandleGetWeight(MainWindowNotification notification)
        {
            UserControl result;

            switch(notification.Command.Name)
            {
                case Names.GoOn:
                    result = new CheckData();
                    break;

                case Names.GoBack:
                    result = new NewPacketAddressReceiver();
                    break;

                default:
                    result = null;
                    break;
            }
            return result;
        }

        private static UserControl HandleNewPacketAddressSender(MainWindowNotification notification)
        {
            UserControl result;

            switch (notification.Command.Name)
            {
                case Names.GoOn:
                    result = new NewPacketAddressReceiver();
                    break;

                case Names.GoBack:
                    result = new StartWindow();
                    break;

                default:
                    result = null;
                    break;
            }
            return result;
        }

        private static UserControl HandleNewPacketAddressReceiver(MainWindowNotification notification)
        {
            UserControl result;

            switch (notification.Command.Name)
            {
                case Names.GoOn:
                    result = new GetWeight();
                    break;

                case Names.GoBack:
                    result = new NewPacketAddressSender();
                    break;

                default:
                    result = null;
                    break;
            }
            return result;
        }


        private static UserControl HandleStartWindow(MainWindowNotification notification)
        {
            UserControl result;

            switch (notification.Command.Name)
            {
                case Names.GetStatus:
                    result = new GetStatus();
                    break;

                case Names.NewPacket:
                    result = new NewPacketAddressSender();
                    break;

                default:
                    result = null;
                    break;
            }

            return result;
        }

        private static UserControl HandleGetStatusWindow(MainWindowNotification notification)
        {
            UserControl result;

            switch (notification.Command.Name)
            {
                case Names.GetStatus:
                    result = null;
                    break;

                case Names.GoBack:
                    result = new StartWindow();
                    break;

                default:
                    result = null;
                    break;
            }

            return result;
        }
    }
}
